﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ExcelFileMonitor.NPOI.Exceptions
{
    [Serializable]
    public class ExcelFileLockedException : Exception
    {
        public string FilePath { get; }
        public int AttemptCount { get; }
        public DateTime ErrorTime { get; } = DateTime.Now;

        public ExcelFileLockedException() : base("Excel文件被锁定")
        {
        }

        public ExcelFileLockedException(string message) : base(message)
        {
        }

        public ExcelFileLockedException(string message, Exception inner) : base(message, inner)
        {
        }

        public ExcelFileLockedException(string filePath, int attemptCount, Exception innerException)
            : base($"文件被锁定，重试{attemptCount}次后仍无法访问: {filePath}", innerException)
        {
            FilePath = filePath;
            AttemptCount = attemptCount;
        }

        protected ExcelFileLockedException(
          System.Runtime.Serialization.SerializationInfo info,
          System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
    }

    [Serializable]
    public class ExcelReadException : Exception
    {
        public string FilePath { get; }
        public string SheetName { get; }
        public DateTime ErrorTime { get; } = DateTime.Now;

        public ExcelReadException() : base("读取Excel文件失败")
        {
        }

        public ExcelReadException(string message) : base(message)
        {
        }

        public ExcelReadException(string message, Exception inner) : base(message, inner)
        {
        }

        public ExcelReadException(string filePath, string sheetName, string message, Exception innerException)
            : base($"读取Excel文件失败 [{filePath}] - 工作表 [{sheetName}]: {message}", innerException)
        {
            FilePath = filePath;
            SheetName = sheetName;
        }

        public ExcelReadException(string filePath, string message, Exception innerException)
            : base($"读取Excel文件失败 [{filePath}]: {message}", innerException)
        {
            FilePath = filePath;
            SheetName = "Unknown";
        }

        protected ExcelReadException(
          System.Runtime.Serialization.SerializationInfo info,
          System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
    }
}
